<?php
	/**
     +=========================================================
     * 评论管理类
     * @package Comment
     +=========================================================
     * @copyright © 2011 nickdraw.com All rights reserved.
     * @author NickDraw(零度温柔) webmaster@206c.net
     * @license http://www.nickdraw.com/license
     * @version V1.2
     +=========================================================
     */
	class CommentAction extends CommonAction {
		function _filter(&$map){
            $map['pid'] = array('eq',0);
        }
		
		public function _before_index(){
			$list_model = M('comment');
			$this->assign("list_model",$list_model);
		}
        
        public function insert(){
            $content = trim($_POST['msg']);
            if (empty($content)){
                $this->error('回复内容不能为空！');
            }else{
                $author_model = M('user');
                $author_array = $author_model->where("id='".$_SESSION[C('USER_AUTH_KEY')]."'")->field('account,nickname,email')->find();
                $val = $_POST;
                $val['msg'] = stripslashes($val['msg']);
                $val['username'] = $author_array['nickname'];
                $val['email'] = $author_array['email'];
                $val['dtime'] = time();
                $val['ip'] = get_client_ip();
                
                //写入数据
                $reply_model = D('comment');
                if ($reply_model->add($val)){
                    $this->assign("jumpUrl", Cookie::get ( '_currentUrl_' ));
                    $this->success("回复成功");
                }else{
                    $this->error("回复失败");
                }
            }
        }
	}
	